package com.heima.kafka.listener;

/**
 * @Author yuan
 * @Date 2023/1/31
 * @ApiNote
 */

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * 消费者接收消息
 */
@Component
public class HelloListener {

    // @KafkaListener(topics = "itcast-topic")
    @KafkaListener(topics = "user-topic")
    public void onMessage(String message) {
        if(!StringUtils.isEmpty(message)) {
            // System.out.println(message);

            // 传递消息为对象
            User user = JSON.parseObject(message, User.class);
            System.out.println(user);
        }
    }
}
